#处理得到的地址数据，生成学校间的连接关系
def get_addr(text):
    t_num = text.find("边缘网")
    if t_num!=-1:
        t_str = text[t_num+4:]
        t_2num = t_str.find('-')
        return t_str[:t_2num]
    else:
        t_num = text.find("城域网")
        if t_num!=-1:
            return text[t_num+4:]
        else:
            t_num = text.find("骨干网")
            if t_num!=-1:
                if len(text[t_num+4:])==0:
                    return '1'
                else:
                    t_list = text[t_num+4:].split('-')
                    return t_list
            else:
                return text

def main():
    f = open("./result/ipv6_location_s2d_norepeat.txt",'r',encoding='utf-8')
    f_write = open("./result/ipv6_school_s2d.txt",'w',encoding='utf-8')
    while True:
        string = f.readline().replace('\n','')
        if len(string)==0:
            break
        string_list = string.split(',')
        if string_list[0]==string_list[1]:
            continue
        elif len(string_list[0])==0 or len(string_list[1])==0:
            continue
        else:
            result0 = get_addr(string_list[0])
            result1 = get_addr(string_list[1])
            print(result0,result1)
            if type(result0)==list and type(result1)==list:
                f_write.write(result0[0]+','+result0[1]+'\n')
                f_write.write(result1[0]+','+result1[1]+'\n')
            elif type(result0)==str and type(result1)==str:
                if result0=='1' or result1=='1':
                    continue
                elif result0==result1:
                    continue
                else:
                    f_write.write(result0+','+result1+'\n')
            elif type(result0)==list or type(result1)==list:
                if type(result0)==list:
                    f_write.write(result0[0]+','+result0[1]+'\n')
                else:
                    f_write.write(result1[0]+','+result1[1]+'\n')
    f.close()
    f_write.close()
    print('finish')

main()